#ifndef _FAKE_SOCKET_H_
#define _FAKE_SOCKET_H_

#include "utils/list.h"

//#define SK_DEBUG

//#ifdef SK_DEBUG
//    #define SK_PRT       os_printf
//    #define SK_WPRT      warning_prf
//#else
//    #define SK_PRT       os_null_printf
//    #define SK_WPRT      warning_prf
//#endif
#ifdef SK_DEBUG
    #define SK_PRT       os_null_printf
    #define SK_WPRT      os_null_printf
#else
    #define SK_PRT       os_null_printf
    #define SK_WPRT      os_null_printf
#endif

typedef int   SOCKET;

typedef struct
{
    struct dl_list data;

    unsigned char *msg;
    int len;

}SOCKET_MSG;

typedef struct
{
    struct dl_list sk_tx_msg;
    struct dl_list sk_rx_msg;
    struct dl_list sk_element;

    SOCKET sk;
}BK_SOCKET;

typedef struct
{
    struct dl_list sk_head;
}SOCKET_ENTITY;

/** sock_type - Socket types
 *
 * Please notice that for binary compat reasons MIPS has to
 * override the enum sock_type in include/linux/net.h, so
 * we define ARCH_HAS_SOCKET_TYPES here.
 *
 * @SOCK_DGRAM - datagram (conn.less) socket
 * @SOCK_STREAM - stream (connection) socket
 * @SOCK_RAW - raw socket
 * @SOCK_RDM - reliably-delivered message
 * @SOCK_SEQPACKET - sequential packet socket
 * @SOCK_PACKET - linux specific way of getting packets at the dev level.
 *        For writing rarp and other similar things on the user level.
 */
enum sock_type {
    SOCK_DGRAM  = 1,
    SOCK_STREAM = 2,
    SOCK_RAW    = 3,
    SOCK_RDM    = 4,
    SOCK_SEQPACKET  = 5,
    SOCK_DCCP   = 6,
    SOCK_PACKET = 10,
};

/*
 *  These 16 ioctls are available to devices via the do_ioctl() device
 *  vector. Each device should include this file and redefine these names
 *  as their own. Because these are device dependent it is a good idea
 *  _NOT_ to issue them to random objects and hope.
 *
 *  THESE IOCTLS ARE _DEPRECATED_ AND WILL DISAPPEAR IN 2.5.X -DaveM
 */

#define SIOCDEVPRIVATE  0x89F0  /* to 89FF */

/*
 *  These 16 ioctl calls are protocol private
 */

#define SIOCPROTOPRIVATE 0x89E0 /* to 89EF */

typedef unsigned short  sa_family_t;

/*
 *  1003.1g requires sa_family_t and that sa_data is char.
 */

struct sockaddr {
    sa_family_t sa_family;  /* address family, AF_xxx   */
    char        sa_data[14];    /* 14 bytes of protocol address */
};


/* Supported address families. */
#define AF_UNSPEC   0
#define AF_UNIX     1   /* Unix domain sockets      */
#define AF_LOCAL    1   /* POSIX name for AF_UNIX   */
#define AF_INET     2   /* Internet IP Protocol     */
#define AF_AX25     3   /* Amateur Radio AX.25      */
#define AF_IPX      4   /* Novell IPX           */
#define AF_APPLETALK    5   /* AppleTalk DDP        */
#define AF_NETROM   6   /* Amateur Radio NET/ROM    */
#define AF_BRIDGE   7   /* Multiprotocol bridge     */
#define AF_ATMPVC   8   /* ATM PVCs         */
#define AF_X25      9   /* Reserved for X.25 project    */
#define AF_INET6    10  /* IP version 6         */
#define AF_ROSE     11  /* Amateur Radio X.25 PLP   */
#define AF_DECnet   12  /* Reserved for DECnet project  */
#define AF_NETBEUI  13  /* Reserved for 802.2LLC project*/
#define AF_SECURITY 14  /* Security callback pseudo AF */
#define AF_KEY      15      /* PF_KEY key management API */
#define AF_NETLINK  16
#define AF_ROUTE    AF_NETLINK /* Alias to emulate 4.4BSD */
#define AF_PACKET   17  /* Packet family        */
#define AF_ASH      18  /* Ash              */
#define AF_ECONET   19  /* Acorn Econet         */
#define AF_ATMSVC   20  /* ATM SVCs         */
#define AF_RDS      21  /* RDS sockets          */
#define AF_SNA      22  /* Linux SNA Project (nutters!) */
#define AF_IRDA     23  /* IRDA sockets         */
#define AF_PPPOX    24  /* PPPoX sockets        */
#define AF_WANPIPE  25  /* Wanpipe API Sockets */
#define AF_LLC      26  /* Linux LLC            */
#define AF_CAN      29  /* Controller Area Network      */
#define AF_TIPC     30  /* TIPC sockets         */
#define AF_BLUETOOTH    31  /* Bluetooth sockets        */
#define AF_IUCV     32  /* IUCV sockets         */
#define AF_RXRPC    33  /* RxRPC sockets        */
#define AF_ISDN     34  /* mISDN sockets        */
#define AF_PHONET   35  /* Phonet sockets       */
#define AF_IEEE802154   36  /* IEEE802154 sockets       */
#define AF_CAIF     37  /* CAIF sockets         */
#define AF_ALG      38  /* Algorithm sockets        */
#define AF_MAX      39  /* For now.. */

/* Protocol families, same as address families. */
#define PF_UNSPEC   AF_UNSPEC
#define PF_UNIX     AF_UNIX
#define PF_LOCAL    AF_LOCAL
#define PF_INET     AF_INET
#define PF_AX25     AF_AX25
#define PF_IPX      AF_IPX
#define PF_APPLETALK    AF_APPLETALK
#define PF_NETROM   AF_NETROM
#define PF_BRIDGE   AF_BRIDGE
#define PF_ATMPVC   AF_ATMPVC
#define PF_X25      AF_X25
#define PF_INET6    AF_INET6
#define PF_ROSE     AF_ROSE
#define PF_DECnet   AF_DECnet
#define PF_NETBEUI  AF_NETBEUI
#define PF_SECURITY AF_SECURITY
#define PF_KEY      AF_KEY
#define PF_NETLINK  AF_NETLINK
#define PF_ROUTE    AF_ROUTE
#define PF_PACKET   AF_PACKET
#define PF_ASH      AF_ASH
#define PF_ECONET   AF_ECONET
#define PF_ATMSVC   AF_ATMSVC
#define PF_RDS      AF_RDS
#define PF_SNA      AF_SNA
#define PF_IRDA     AF_IRDA
#define PF_PPPOX    AF_PPPOX
#define PF_WANPIPE  AF_WANPIPE
#define PF_LLC      AF_LLC
#define PF_CAN      AF_CAN
#define PF_TIPC     AF_TIPC
#define PF_BLUETOOTH    AF_BLUETOOTH
#define PF_IUCV     AF_IUCV
#define PF_RXRPC    AF_RXRPC
#define PF_ISDN     AF_ISDN
#define PF_PHONET   AF_PHONET
#define PF_IEEE802154   AF_IEEE802154
#define PF_CAIF     AF_CAIF
#define PF_ALG      AF_ALG
#define PF_MAX      AF_MAX

#define SOL_SOCKET  1

#define SO_DEBUG    1
#define SO_REUSEADDR    2
#define SO_TYPE     3
#define SO_ERROR    4
#define SO_DONTROUTE    5
#define SO_BROADCAST    6
#define SO_SNDBUF   7
#define SO_RCVBUF   8
#define SO_SNDBUFFORCE  32
#define SO_RCVBUFFORCE  33
#define SO_KEEPALIVE    9
#define SO_OOBINLINE    10
#define SO_NO_CHECK 11
#define SO_PRIORITY 12
#define SO_LINGER   13
#define SO_BSDCOMPAT    14
/* To add :#define SO_REUSEPORT 15 */
#define SO_PASSCRED 16
#define SO_PEERCRED 17
#define SO_RCVLOWAT 18
#define SO_SNDLOWAT 19
#define SO_RCVTIMEO 20
#define SO_SNDTIMEO 21

/* Security levels - as per NRL IPv6 - don't actually do anything */
#define SO_SECURITY_AUTHENTICATION      22
#define SO_SECURITY_ENCRYPTION_TRANSPORT    23
#define SO_SECURITY_ENCRYPTION_NETWORK      24

#define SO_BINDTODEVICE 25

/* Socket filtering */
#define SO_ATTACH_FILTER        26
#define SO_DETACH_FILTER        27

#define SO_PEERNAME             28
#define SO_TIMESTAMP        29
#define SCM_TIMESTAMP       SO_TIMESTAMP

#define SO_ACCEPTCONN       30

#define SO_PEERSEC      31
#define SO_PASSSEC      34
#define SO_TIMESTAMPNS      35
#define SCM_TIMESTAMPNS     SO_TIMESTAMPNS

#define SO_MARK         36

#define SO_TIMESTAMPING     37
#define SCM_TIMESTAMPING    SO_TIMESTAMPING

#define SO_PROTOCOL     38
#define SO_DOMAIN       39

#define SO_RXQ_OVFL             40

typedef struct socket_type_st {
    unsigned char type;
    unsigned char vif_index;
}S_TYPE_ST,*S_TYPE_PTR;

extern SOCKET fsocket_init(int af, int type, int protocol);
extern int fsocket_send(SOCKET sk, const unsigned char *buf, int len, S_TYPE_PTR type);
extern int fsocket_recv(SOCKET sk, const unsigned char *buf, int len, int flag);
extern void fsocket_close(SOCKET sk);
extern int ke_sk_send(SOCKET sk, const unsigned char *buf, int len, int flag);
extern int ke_sk_recv(SOCKET sk, const unsigned char *buf, int len, int flag);
extern BK_SOCKET *sk_get_sk_element(SOCKET sk);
extern int ke_sk_recv_peek_next_payload_size(SOCKET sk);
extern int fsocket_peek_recv_next_payload_size(SOCKET sk);
extern int ke_sk_send_peek_next_payload_size(SOCKET sk);

#endif // _FAKE_SOCKET_H_
// eof

